import {
	storage
} from '@/utils/base'
import {
	STATIC_URL
} from '@/config/app.config.js'

// 获取设备信息
export const getDeviceInfo = () => {
	const deviceInfo = {}
	const systemInfo = uni.getSystemInfo()
	// 手机品牌
	deviceInfo.brand = systemInfo.brand
	// 手机型号
	deviceInfo.model = systemInfo.model
	// 客户端平台 ios/Android
	deviceInfo.platform = systemInfo.platform
	// #ifdef APP-PLUS
	return plus.device.getInfo({
		success: function(res) {
			// 设备的生产厂商
			deviceInfo.vendor = plus.device.vendor
			// 设备的国际移动设备身份码
			deviceInfo.imei = res.imei
			// 设备的国际移动用户识别码
			deviceInfo.imsi = res.imsi
			// 设备的唯一标识
			deviceInfo.uuid = res.uuid
			storage.set('deviceInfo', deviceInfo)
		},
		fail: function(e) {
			console.log(e)
			storage.set('deviceInfo', deviceInfo)
		}
	})
	//#endif
	storage.set('deviceInfo', deviceInfo)
}

export const $rc = {
	getSource(path) {
		return `${STATIC_URL}${path}`
	},
	// 页面路由跳转
	navigateTo(url) {
		uni.navigateTo({
			url
		});
	},
	//关闭当前页面，跳转到应用内的某个页面。
	redirectTo(url) {
		uni.redirectTo({
			url
		})
	},
	// tab路由跳转
	switchTab(url) {
		uni.switchTab({
			url
		})
	},

	navigateBack(delta) {
		uni.navigateBack({
			delta
		})
	},
	uBtnBgTransparent: {
		background: 'transparent !important'
	},

	// 导航到webview页面
	toWebViewPage(url) {
		uni.navigateTo({
			url: `/pages/account/privacy-rules/privacy-rules?url=${url}`
		});
	},
}
